package com.globallogic.jbtask4;

import java.util.Scanner;

public class CalendarSeeker {

    private class DateInfo {

       public int day;
       public int month;
       public int year;
 
    }

    
    public DateInfo getDateInfo() {
        
        Scanner input = new Scanner(System.in);        
        String[] dateData; 
        DateInfo dateInfo = new DateInfo();
        
        System.out.println("Enter date in format <dd month yyyy>, please");

        dateData = input.nextLine().split(" ");
        
        try {

            dateInfo.day = Integer.parseInt(dateData[0]);
            dateInfo.month = Month.getMonthNumber(dateData[1]);
            dateInfo.year = Integer.parseInt(dateData[2]);
            
        } catch (NumberFormatException e) {

            System.out.println("Illegal format of day or year. " + e.getMessage());

        } catch (MonthFormatException e) {

            System.out.println(e.getMessage());

        }


        return dateInfo;
    }
    
    public String getDayName(DateInfo dateInfo) {
        
        int a;
        int y;
        int m;
        int dayNumber;

        a = (14 - dateInfo.month) / 12;     
        y = dateInfo.year - a;
        m = dateInfo.month + 12 * a - 2;
    
        dayNumber = (7000 + (dateInfo.day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12)) % 7;
        
        return Day.getDayName(dayNumber);
    }

    
    public static void main(String[] args) {

        DateInfo dateInfo;
        String dayName;
        CalendarSeeker calendarSeeker = new CalendarSeeker();
       
        dateInfo = calendarSeeker.getDateInfo();
        dayName = calendarSeeker.getDayName(dateInfo);

        System.out.println("Entered day is " + dayName); 
   
    }

}
